<?php

class newsletter_widget extends iKernel{
	function newsletter_widget(){
			global $relativeslash, $current_language, $locale;
		$tpl = new Template;
		$this->title = "News Letter";
		$this->content = "

		<small>Sign up for PHPHome CMS newsletter<br />get the latest news directly into your mailbox<br />
		If you already signed up, you can enter your email again to unsign for the newsletters</small>
		<br />
				<form method='post'>
		<input type='text' name='email' style='width: 100%;' /><br />
		<input type='submit' name='sign_newsletter' value='Sign Up' />
		</form>
		";
		
		if(isset($_POST['sign_newsletter'])){
			if(!empty($_POST['email'])){
				$db = new DB("newsletter_emails");
				$db->select("email='".$_POST['email']."'");
				if($db->numRows() == "0"){
					
					$db = new DB("newsletter_emails");
					$db->email = $_POST['email'];
					$db->insert();
					
					$this->content->content .="<br /><strong>".$_POST['email']." has been added to the newsletter list</strong>";
				}else{
					$db = new DB("newsletter_emails");
					$db->delete("email='".$_POST['email']."'");
					$this->content .="<br /><strong>".$_POST['email']." has been removed to the newsletter list</strong>";
				}
			}else{
				$this->content .= "<br /><strong>You need to enter your email first</strong>";
			}
		}

		$tpl->title = $this->title;
		$tpl->content = $this->content;
		$tpl->Build("view/modules");
	}

}


?>